package edu.uoc.tds.cliente;


import java.rmi.RemoteException;

import javax.swing.*;

import java.awt.Rectangle;
import javax.swing.JOptionPane; 
import javax.swing.JComboBox;
import java.util.*;

import edu.uoc.tds.common.MostrarCombo;
import edu.uoc.tds.common.RemotoInterface;
import edu.uoc.tds.common.UtilLenguaje;



public class PantallaAltaFactura extends javax.swing.JPanel {

    private RemotoInterface objServeis = null;
    private static final long serialVersionUID = 1L;
    private JComboBox comboEvento = null;
    private JComboBox comboUniversidad = null;
    private JComboBox comboPais = null;
    private JButton botonGuardar = null;
    private JButton botonCancelar = null;
    private JTextField fechaValor = null;
    private JTextArea descripcion = null;
    private JTextField importe = null;
    private UtilLenguaje txt = null;
    private JLabel labelEvento = null;
    private JLabel labelProveedor = null;
    private JLabel labelConcepto = null;
    private JLabel labelFecha = null;
    private JLabel labelDescripcion = null;
    private JLabel labelImporte = null;
    JScrollPane textScroll=null;

    public PantallaAltaFactura(RemotoInterface pObjServeis) throws RemoteException {
        super();
        objServeis = pObjServeis;
        initComponents();

    }

    private JComboBox getComboEvento() {

        if (comboEvento == null) {
            comboEvento = new JComboBox();
            Vector<MostrarCombo> vTipoEventos;
            try {
               vTipoEventos = objServeis.listaTipoEventos();
                comboEvento = new JComboBox(vTipoEventos);
                comboEvento.setBounds(new Rectangle(290, 20, 275, 25));
            } catch (RemoteException eRe) {
                JOptionPane.showMessageDialog(null,
                        txt.getMessage("pantAlta.error.remoto") + "\n" + eRe.getMessage(),
                        txt.getMessage("pantAlta.error"), JOptionPane.ERROR_MESSAGE);

            }

        }
        return comboEvento;
    }


     private JComboBox getComboUniversidad() {

        if (comboUniversidad == null) {
            comboUniversidad = new JComboBox();
            Vector<MostrarCombo> vUniversidad=null;
            try {
                vUniversidad = objServeis.listaUniversidades();

                comboUniversidad = new JComboBox(vUniversidad);
                comboUniversidad.setBounds(new Rectangle(290, 60, 275, 25));
            } catch (Exception eRe) {
                JOptionPane.showMessageDialog(null,
                        txt.getMessage("pantAlta.error.remoto") + "\n" + eRe.getMessage(),
                        txt.getMessage("pantAlta.error"), JOptionPane.ERROR_MESSAGE);

            } 

        }
        return comboUniversidad; 
    }
  

     private JComboBox getComboPais() {

        if (comboPais == null) {
            comboPais = new JComboBox();
            Vector<MostrarCombo> vPais=null;
            try {
                vPais = objServeis.listaPaises();

                comboPais = new JComboBox(vPais);
                comboPais.setBounds(new Rectangle(0, 20, 275, 25));
            } catch (Exception eRe) {
                JOptionPane.showMessageDialog(null,
                        txt.getMessage("pantAlta.error.remoto") + "\n" + eRe.getMessage(),
                        txt.getMessage("pantAlta.error"), JOptionPane.ERROR_MESSAGE);

            }

        }
        return comboPais;
    }

    private void initComponents() {

        this.setLayout(null);
        this.setBounds(new Rectangle(0, 0, 800, 300));

        this.add(getComboEvento(), null);
        this.add(getComboUniversidad(), null);
        this.add(getComboPais(), null);


        descripcion = new JTextArea(18, 15);
        textScroll=new JScrollPane(descripcion);
        textScroll.setBounds(new Rectangle(290, 180, 280, 25));
        this.add(textScroll);

        importe = new JTextField(10);
        importe.setBounds(new Rectangle(290, 220, 150, 25));
        this.add(importe); 

        labelEvento = new JLabel();
        labelEvento.setBounds(new Rectangle(150, 20, 100, 20));
        labelEvento.setText(txt.getMessage("pantAlta.label.evento"));
        this.add(labelEvento);

        labelProveedor = new JLabel();
        labelProveedor.setBounds(new Rectangle(150, 60, 100, 20));
        labelProveedor.setText(txt.getMessage("pantAlta.label.proveedor"));
        this.add(labelProveedor);


        labelConcepto = new JLabel();
        labelConcepto.setBounds(new Rectangle(150, 100, 100, 20));
        labelConcepto.setText(txt.getMessage("pantAlta.label.concepto"));
        this.add(labelConcepto);

        labelDescripcion = new JLabel();
        labelDescripcion.setBounds(new Rectangle(150, 180, 100, 20));
        labelDescripcion.setText(txt.getMessage("pantAlta.label.descripcion"));
        this.add(labelDescripcion);

        labelFecha = new JLabel();
        labelFecha.setBounds(new Rectangle(150, 140, 100, 20));
        labelFecha.setText(txt.getMessage("pantAlta.label.fechaValor"));
        this.add(labelFecha);

        labelImporte = new JLabel();
        labelImporte.setBounds(new Rectangle(150, 220, 100, 20));
        labelImporte.setText(txt.getMessage("pantAlta.label.importe"));
        this.add(labelImporte);

        fechaValor = new JTextField(10);
        fechaValor.setBounds(new Rectangle(290, 140, 150, 25));
        this.add(fechaValor);

        this.add(getBotonCancelar(), null);
        this.add(getBotonGuardar(), null);
    }

    private JButton getBotonGuardar() {
        if (botonGuardar == null) {
            botonGuardar = new JButton();
            botonGuardar.setBounds(new Rectangle(290, 290, 275, 30));
            botonGuardar.setText(txt.getMessage("pantAlta.boton.guardar"));
            botonGuardar.addActionListener(new java.awt.event.ActionListener() {

                public void actionPerformed(java.awt.event.ActionEvent e) {
                  /*  Integer exist = AltaFactura();
                    if (exist == 0) {
                        JOptionPane.showMessageDialog(null,
                                txt.getMessage("pantAlta.guardar.ok"),
                                txt.getMessage("pantAlta.guardar"), JOptionPane.WARNING_MESSAGE);
                    }*/
                }
            });
        }
        return botonGuardar;
    }

    private JButton getBotonCancelar() {
        if (botonCancelar == null) {
            botonCancelar = new JButton();
            botonCancelar.setBounds(new Rectangle(10, 290, 275, 30));
            botonCancelar.setText(txt.getMessage("pantAlta.boton.cancelar"));
            botonCancelar.addActionListener(new java.awt.event.ActionListener() {

                public void actionPerformed(java.awt.event.ActionEvent e) {
                    try {
                        PantallaAltaFactura.this.setVisible(false);

                    } catch (Throwable e1) {
                        JOptionPane.showMessageDialog(null,
                                txt.getMessage("pantAlta.cancelar.err") + "\n" + e1.getMessage(),
                                txt.getMessage("pantAlta.cancelar.title.err"), JOptionPane.ERROR_MESSAGE);
                    }
                }
            });
        }
        return botonCancelar;
    }

    
}
 